﻿using JNPF.Basics.Logic;
using JNPF.Basics.Models.System.Dtos.Log;
using JNPF.Utils;
using JNPF.Utils.Controller;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace JNPF.Basics.Controller
{
    /// <summary>
    /// 系统日志
    /// 版 本：V3.0.0
    /// 版 权：引迈信息技术有限公司（https://www.jnpfsoft.com）
    /// 作 者：JNPF开发平台组
    /// 日 期：2017.09.21
    /// </summary>
    [Route("api/System/[controller]")]
    public class LogController : BaseApiController
    {
        private LogBll logBll = new LogBll();

        #region GET
        /// <summary>
        /// 获取系统日志列表-登录日志（带分页）
        /// </summary>
        /// <param name="input">请求参数</param>
        /// <param name="Type">分类</param>
        /// <returns></returns>
        [HttpGet("{Type}")]
        public async Task<ResponseResult> GetList([FromQuery] LogListQuery input, int Type)
        {
            PageInput requestParam = input.MapTo<PageInput>();
            requestParam.queryJson = new { input.endTime, input.startTime }.ToJson();
            var data = await logBll.GetList(Type, requestParam);
            object output = null;
            if (Type == 1)
            {
                var outputLogin = new PageResult<LogLoginOutput>
                {
                    list = data.list.MapToList<LogLoginOutput>(),
                    pagination = data.pagination
                };
                return Success(outputLogin);
            }
            if (Type == 4)
            {
                var outputException = new PageResult<LogExceptionOutput>
                {
                    list = data.list.MapToList<LogExceptionOutput>(),
                    pagination = data.pagination
                };
                return Success(outputException);
            }
            if (Type == 5)
            {
                var outputRequest = new PageResult<LogRequestOutput>
                {
                    list = data.list.MapToList<LogRequestOutput>(),
                    pagination = data.pagination
                };
                return Success(outputRequest);
            }
            return Success(output);
        }
        #endregion

        #region POST
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="input">请求参数</param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ResponseResult> Delete([FromBody] LogDelInput input)
        {
            await logBll.Delete(input.ids);
            return Success("删除成功");
        }
        #endregion
    }
}
